<?php

namespace app\interior\controller;

use app\health\model\HealthUser;
use app\health\model\MasterUser;

class User extends BaseInterior
{
    /**
     * 更新小程序用户手机号
     * @Author 张旭鹏
     * @DateTime 2023-07-05
     */
    public function update_mobile()
    {
        $masterUserId = request()->post('master_user_id');
        if (!$masterUserId) {
            return json(['code' => 0, 'msg' => '请传入用户ID']);
        }
        $masterUser = MasterUser::where('id', $masterUserId)->find();
        if (!$masterUser) {
            return json(['code' => 0, 'msg' => '主用户不存在']);
        }
        $healthUser = HealthUser::where('master_user_id', $masterUserId)->find();
        if (!$healthUser) {
            return json(['code' => 0, 'msg' => '小程序用户未注册']);
        }
        $healthUser->save(['mobile' => $masterUser['mobile']]);
        return json(['code' => 1, 'msg' => '更新成功']);
    }
}
